﻿using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;

namespace Cubicle.Core.Processors.Construct
{
    [Export("Cubicle.Processors.Construct.ConstructQueue", typeof(IProcessor<InstructionRequest>))]
    [ExportMetadata("Name", "ConstructQueue")]
    [ExportMetadata("Description", "Filters construction requests.")]
    public class ConstructQueue : ConditionalQueue<InstructionRequest>
    {
        public override bool Condition(InstructionRequest input)
        {
            var reqType = input.Type();
            return reqType.HasFlag(RequestType.CustomConstruct) || reqType.HasFlag(RequestType.Construct);
        }

        public override InstructionRequest ProcessQueue(InstructionRequest input)
        {
            // If the key is null, generate one
            if (input.Inst.Key == null && Condition(input)) input.Inst.Key = "_";
            return base.ProcessQueue(input);            
        }

    }
}